import time
from telnetlib import EC

from selenium import webdriver
from selenium.webdriver.common import by
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

#获取浏览器对象打开网页
driver=webdriver.Chrome('./chromedriver.exe')

driver.get('https://quote.eastmoney.com/center/gridlist.html#newshares')
for i in range(1,10):

    tr_list = driver.find_elements(By.XPATH, "//table[@id='table_wrapper-table']//tbody/tr")
# 如果是第十页的话就特殊处理
    if(i==10):
        # 获取到当前页面的数据
        for tr in tr_list:
            print(tr.find_element(By.XPATH, "./td[@class='mywidth']/a").text)  # 名字
            print(tr.find_element(By.XPATH, "./td[8]").text)  # 成交量
            print(tr.find_element(By.XPATH, "./td[11]/span").text)  # 最高
            print(tr.find_element(By.XPATH, "./td[13]/span").text)  # 今开
            print(tr.find_element(By.XPATH, "./td[15]").text)  # 换手
            print(tr.find_element(By.XPATH, "./td[16]").text)  # 市营
    else:
        # 获取到当前页面的数据
        for tr in tr_list:
            print(tr.find_element(By.XPATH, "./td[@class='mywidth']/a").text)  # 名字
            print(tr.find_element(By.XPATH, "./td[8]").text)  # 成交量
            print(tr.find_element(By.XPATH, "./td[11]/span").text)  # 最高
            print(tr.find_element(By.XPATH, "./td[13]/span").text)  # 今开
            print(tr.find_element(By.XPATH, "./td[15]").text)  # 换手
            print(tr.find_element(By.XPATH, "./td[16]").text)  # 市营
        # 到下一页
        driver.find_element(By.XPATH, "//div[@id='main-table_paginate']/a[2]").click()
        time.sleep(3)

